/*****************************************************************************************
  Project   : The Impact of Unions on Non-union Wage Setting: Threats and Bargaining
  Authors   : David A. Green, Ben M. Sand, Iain G. Snoddy, Jeanne Tschopp
  Date      : August 2025
  Output    : Data for Figure 6 -- Inequality between groups
  Notes     : This script should be run after main data cleaning and variable construction
*****************************************************************************************/


// Data Figure 6 

// extract parts needed for group inequality comparison
// save for R figure.

cap program drop ineq 
program define ineq
syntax, grp(string) 

use "${wd}/decomp_grp_`grp'_case_6.dta", clear 

// variables for inequality
	gen Total = part1 + part2 + deunion
	gen Wage = W_obs0 * ( 1 - union_share ) + W_obs1 * union_share

	keep year Total Wage 

	gen CF = Wage - Total

	gen  grp = "`grp'"
	
	drop if year == 5
	
	
end

// Groups used in figure
tempfile temp
foreach grp in high10   HighMen10 HighWomen10       low10    LowMen10  LowWomen10       men10     women10 {
	
	ineq, grp(`grp')	
	capture append using `temp'
	save `temp', replace
	
}

save "${wd}/ineq_all_grp_v1.dta", replace

